﻿//209.长度最小的子数组
class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int sum = 0, size = nums.size(), minlen = size + 1;
        for (int left = 0, right = 0; right < size; right++)
        {
            sum += nums[right];
            while (sum >= target)
            {
                minlen = min(right - left + 1, minlen);
                sum -= nums[left];
                left++;
            }
        }
        return minlen == size + 1 ? 0 : minlen;
    }
};
